﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using DAO;
using System.Data;

namespace APA_DAO
{
    public class MotoDao
    {
        public MotoDao()
        {
            new SqlHelper();
        }

        public bool insertMoto(int soThuePhong, string bienSo, string soKhung, string soMay, string chuSoHuu)
        {
            return SqlHelper.ExecuteNonQuery("SP_INSERT_MOTO", CommandType.StoredProcedure,
                "@TEN_CHU_SO_HUU", chuSoHuu,
                "@SO_XE", bienSo,
                "@SO_KHUNG", soKhung,
                "@SO_MAY", soMay,
                "@SO_THUE_PHONG", soThuePhong,
                "@USR_ID", LoginDao.userID);
        }

        public DataRow getMotoById(int id)
        {
            DataTable table = SqlHelper.ExecuteDataTable("SP_GET_MOTO_INFOR_BY_ID", CommandType.StoredProcedure,
                "@ID", id);
            if (table != null)
            {
                return table.Rows[0];
            }
            return null;
        }

        public bool updateMoto(int id,  string bienSo, string soKhung, string soMay, string chuSoHuu)
        {
            return SqlHelper.ExecuteNonQuery("SP_UPDATE_MOTO", CommandType.StoredProcedure,
                "@ID", id,
                "@CHU_SO_HUU", chuSoHuu,
                "@SO_XE", bienSo,
                "@SO_KHUNG", soKhung,
                "@SO_MAY", soMay);
        }

        public DataTable getMotos(int soThuePhong)
        {
            return SqlHelper.ExecuteDataTable("SP_GET_MOTOS_BY_SO_THUE_PHONG", CommandType.StoredProcedure,
                "@ID", soThuePhong);
        }

        public bool deleteMoto(int id)
        {
            return SqlHelper.ExecuteNonQuery("SP_DELETE_MOTO", CommandType.StoredProcedure,
                "@ID", id);
        }
    }
}
